var Loader = require("wy-Loader")
cc.Class({
    extends: cc.Component,
    properties: {
        TiledBG:cc.Sprite,
        TiledLB:cc.Label,
        IndexLB:cc.Label,
        SelectBG:cc.SpriteFrame,
        Data:
        {
            get()
            {
                return this._Data;
            },
            set(value)
            {
                this._Data=value;
            }
        },
        SelectState:
        {
            get()
            {
                return this._SelectState;
            },
            set(value)
            {
                this._SelectState = value;
                if(!this.SelectBG)this.SelectBG=this.node.getChildByName("selectedBT").getComponent(cc.SpriteFrame);
                this.SelectBG.active=value;
            }
        },
        OnStateChange:
        {
            get()
            {
                return this._OnStateChange;
            },
            set(value)
            {
                this._OnStateChange=value;
            }
        }
    },
    UpdateTiledData(data)
    {
        this.Data=data;
        if(!this.TiledLB)this.TiledLB=this.node.getChildByName("TiledLB");
        if(!this.IndexLB)this.IndexLB=this.node.getChildByName("IndexLB");
        if(!this.TiledBG)this.TiledBG=this.node.getChildByName("TiledBG");
        this.TiledLB.string=data.TiledID
        this.IndexLB.string="Idx:"+data.index;
        this.SelectState=data.SelectState;
        if(this._url == data.imgUrl) return ;
        this.TiledBG.spriteFrame=new cc.SpriteFrame(Loader.getImgResource(data.imgUrl));
        this._url = data.imgUrl;
    },
    SetSelectTiledState(state)
    {
        this.SelectState=state;
        if(this.Data)this.Data.SelectState=state;
        if(!this.Data) return ;
        if(this.OnStateChange)this.OnStateChange(this.Data);
    },
    OnSelectItem()
    {
        this.SetSelectTiledState(!this.SelectState)
    },
    onLoad()
    {
        this.SelectBG.on("touchend",this.OnSelectItem,this);
    }

    // update (dt) {},
});
